package uns.fit.gis.mapobj;

public class Segment {
	private int ids;
	private int[] points;
        private int info;//  4 byte following: type, type2, level, other

	private int minXY;
	private int maxXY;
	
	private int ends; //id of two crossroadses
	private int length;

	public Segment()
	{
		setMinX(Integer.MAX_VALUE);
		setMinY(Integer.MAX_VALUE);
		setMaxX(Integer.MIN_VALUE);
		setMaxY(Integer.MIN_VALUE);
	}

	public int getId() {
		return ((ids >> 16) & 0xFFFF);
	}

	public void setId(int id) {
		ids = (((id) & 0xFFFF) << 16) | (ids & 0xFFFF);
	}

	public int getPathId() {
		return (ids & 0xFFFF);
	}

	public void setPathId(int pathId) {
		ids = (ids & 0xFFFF0000) | (pathId & 0xFFFF);
	}

	public byte getType() {
            return (byte)((info >> 24) & 0xFF);
        }

        public void setType(byte type) {
             info = (type << 24) | (info & 0xFFFFFF);
        }

        public byte getType2() {
             return (byte)((info >> 16) & 0xFF);
        }

        public void setType2(byte type2) {
             info = (type2 << 16) | (info & 0xFF00FFFF);
        }

        public byte getLevel() {
             return (byte)((info >> 8) & 0xFF);
        }

        public void setLevel(byte level) {
             info = (level << 8) | (info & 0xFFFF00FF);
        }

        public byte getOther() {
            return (byte)(info & 0xFF);
        }

        public void setOther(byte other) {
            info = other | (info & 0xFFFFFF00);
        }

	public void setNumberOfPoints(int size) {
            points = new int[size];
        }

        public int getNumberOfPoints() {
            return points.length;
        }

        public void setX(int index, short x) {
            points[index] = ((((int)x) & 0xFFFF) << 16) | (points[index] & 0xFFFF);
        }

        public int getX(int index) {
            return ((points[index] >> 16) & 0xFFFF);
        }

        public void setY(int index, short y) {
            points[index] = (points[index] & 0xFFFF0000) | (((int)y) & 0xFFFF);
        }

        public int getY(int index) {
            return (points[index] & 0xFFFF);
        }

	public int getMinX() {
		return ((minXY >> 16) & 0xFFFF);
	}

	public void setMinX(int minX) {
		this.minXY = ((minX & 0xFFFF) << 16) | (this.minXY & 0xFFFF);
	}

	public int getMinY() {
		return (minXY & 0xFFFF);
	}

	public void setMinY(int minY) {
		this.minXY = (this.minXY & 0xFFFF0000) | (minY & 0xFFFF);
	}

	public int getMaxX() {
		return ((maxXY >> 16) & 0xFFFF);
	}

	public void setMaxX(int maxX) {
		this.maxXY = ((maxX & 0xFFFF) << 16) | (this.maxXY & 0xFFFF);
	}

	public int getMaxY() {
		return (maxXY & 0xFFFF);
	}

	public void setMaxY(int maxY) {
		this.maxXY = (this.maxXY & 0xFFFF0000) | (maxY & 0xFFFF);
	}

	public void setCross0(short x) {
        ends = ((((int)x) & 0xFFFF) << 16) | (ends & 0xFFFF);
    }

    public int getCross0() {
        return ((ends >> 16) & 0xFFFF);
    }

    public void setCross1(short y) {
        ends = (ends & 0xFFFF0000) | (((int)y) & 0xFFFF);
    }

    public int getCross1() {
        return (ends & 0xFFFF);
    }

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}
	
	public void reverseAllPoints() {
		int[] p = new int[points.length];
		for(int i = 0; i < p.length; i ++)
			p[i] = points[p.length - i - 1];
		points = p;
	}
}
